<style type="text/css">
    .demo-upload-list {
        display: inline-block;
        width: 60px;
        height: 60px;
        text-align: center;
        line-height: 60px;
        border: 1px solid transparent;
        border-radius: 4px;
        overflow: hidden;
        background: #fff;
        position: relative;
        box-shadow: 0 1px 1px rgba(0, 0, 0, .2);
        margin-right: 4px;
    }

    .demo-upload-list img {
        width: 100%;
        height: 100%;
    }

    .demo-upload-list-cover {
        display: none;
        position: absolute;
        top: 0;
        bottom: 0;
        left: 0;
        right: 0;
        background: rgba(0, 0, 0, .6);
    }

    .demo-upload-list:hover .demo-upload-list-cover {
        display: block;
    }

    .demo-upload-list-cover i {
        color: #fff;
        font-size: 20px;
        cursor: pointer;
        margin: 0 2px;
    }

    .selected-search {
        box-shadow: 0 1px 6px rgba(0, 0, 0, .2);
        height: 200px;
        width: 260px;
        position: relative;
        border-radius: 4px;
    }

    .selected-search .search-action {
        position: absolute;
        top: 10px;
        left: 10px;
        right: 10px;
    }

    .selected-search .selected-arr {
        position: absolute;
        top: 50px;
        left: 20px;
        right: 20px;
        bottom: 10px;
        overflow: scroll;
    }

    .select-click {
        border: 1px solid #dddee1;
        border-radius: 4px;
        padding: 0 10px;
        margin-bottom: 10px;
    }

    .selected-search .selected-arr .selected-item {
        /*border-bottom: 1px solid #dfdfdf;*/
    }
</style>
<template>
    <i-form v-if="formIsShow ==1" ref="formValidate" :model="formValidate" :rules="ruleValidate" :label-width="100" style="width: 40%">
        <template v-for="(item,index) in dataModel">
            <Form-item :label="item.value" :prop="item.Keyname">
                <i-input v-model="formValidate[item.Keyname]" :placeholder="'请输入'+ item.value"></i-input>
            </Form-item>
        </template>
        <Form-item>
            <i-button @click="handleSubmit('formValidate')" type="primary">提交</i-button>
            <i-button   style="margin-left: 8px">取消</i-button>
        </Form-item>
    </i-form>

</template>
<script>
    import apiUtil from '../../assets/utils/api_util';

    export default {
        data() {
            return {
                formValidate: {},
                ruleValidate: {},
                dataModel: [],
                keyword: '',
                formIsShow:2,
                //值班人员选择操作
                principalId: '',
                principalArr: [],
                personalName: '请选择组织',
                selectPeopelIsShow: false,
            }
        },
        mounted: function () {
            this.getDetail();
        },

        created:function(){
            this.getListAllUserExt();
        },

        methods: {
            handleSubmit(name) {

                let that = this;
                let model = this.$refs[name].model;
                console.log('提交数据:', model);
                this.$refs[name].validate((valid) => {
                    that.addData(model);
                })
            },
            // 获取拓展信息字段
            getListAllUserExt: function (data) {
                let that = this;
                let para = {};
                this.$Loading.start();

                apiUtil.get(that, apiUtil.urls.ListAllUserExt, para, function (res) {
                    that.$Loading.finish();
                    res.Msg.forEach(function (item, index) {
                        let itemSub = {};
                        itemSub.Keyname = item.Keyname;
                        itemSub.value = item.Value;
                        that.dataModel.push(itemSub);
                    });
                    if(that.dataModel.length > 0){
                        that.getDetail(that.dataModel,1);
                    }
                });
            },
            getDetail: function (data,isShow) {
                let that = this;
                that.$Loading.start();

                let para = {
                    // id: '74b7f477-0fcd-419c-b30b-8ea8154b8b34',
                    id:that.$route.query.id,
                };

                let params = that.$qs.stringify(para);
                apiUtil.get(that, apiUtil.urls.userClientDetail, para, function (res) {
                    that.$Loading.finish();

                    console.log('data:',data);
                    data.forEach(function (item,index) {
                        res.Msg.ExtInfo.forEach(function (item2,index2) {
                            if(item.Keyname == item2.Extkey){
                                that.formValidate[item.Keyname] = item2.Extvalue
                            }
                        })

                    });
                    that.formIsShow =isShow;
                    console.log('formValidate:',that.formValidate);
                });
            },
            getSearchData() {
                let that = this;

                let para = {
                    keyword: this.keyword,
                };

                this.$Loading.start();

                apiUtil.get(that, apiUtil.urls.OrganSearch, para, function (res) {
                    that.$Loading.finish();
                    that.principalArr = res.Msg;
                });
            },
            choosePeople: function (id, name) {
                this.principalId = id;
                this.personalName = name;
                this.selectPeopelIsShow = false;

            },
            //添加
            addData: function (model) {
                let that = this;

                let postJosn = [];

                // model.organizationId = this.principalId;

                for (let i in model) {
                    let postValue = {
                        'extkey': '',
                        'extValue': '',
                    };

                    postValue.extkey = i;
                    postValue.extValue = model[i];

                    postJosn.push(postValue);
                }

                let apiPost = {
                    id: this.$route.query.id,
                    extJson: JSON.stringify(postJosn),
                };


                let params = that.$qs.stringify(apiPost);
                this.$Loading.start();

                apiUtil.post(that, apiUtil.urls.userCreateStep4, params, function (res) {
                    that.$Loading.finish();

                    that.$Message.success('成功 ');

                });
            },

        }
    }
</script>
